package com.china_goldcard.igas.ui.core;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.DimenRes;
import android.support.annotation.IntegerRes;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.Window;

import com.china_goldcard.igas.R;
import com.china_goldcard.igas.utils.StatusBarCompat;
import com.china_goldcard.igas.widget.slideclose.SlidingLayout;


/**
 * 基础的activity
 */
public class BaseActivity extends FragmentActivity {

    protected String TAG = this.getClass().getName();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        // 调用父类的方法
        super.onCreate(savedInstanceState);
        // 禁止横屏
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        // 设置页面过渡效果
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        // 布局文件
        if (layoutResource()!=null){
            setContentView(layoutResource().intValue());
            if (hasNavBar()) {
                StatusBarCompat.compat(this, getResources().getColor(R.color.nav_bg_color));
            }
        }
        if (supportSlideClose()){
            SlidingLayout slidingLayout = new SlidingLayout(this);
            slidingLayout.bindActivity(this);
        }
    }

    /**
     * 是否支持滑动关闭页面
     * @return
     */
    protected boolean supportSlideClose(){
        return false;
    }

    /**
     * 是否需要显示navbar
     * @return
     */
    protected boolean hasNavBar(){
         return false;
    }

    /**
     * 资源文件
     * @return
     */
    protected Integer layoutResource(){
        return null;
    }

    /**
     * 页面跳转
     * @param target
     * @param data
     */
    protected void toPage(Class<? extends BaseActivity> target,Bundle data){
        Intent intent = new Intent(this,target);
        if (data == null){
            data = new Bundle();
        }
        intent.putExtras(data);
        startActivity(intent);
    }

    protected int dimen(@DimenRes int resId) {
        return (int) getResources().getDimension(resId);
    }

    protected int color(@ColorRes int resId) {
        return getResources().getColor(resId);
    }

    protected int integer(@IntegerRes int resId) {
        return getResources().getInteger(resId);
    }

}
